<template>
  <el-dialog :title="$t('agv.changePriority')" v-model="visible" :width="'500px'" draggable
             :close-on-click-modal="false">
    <el-form :model="form" ref="formRef" label-width="120px" size="large">
      <el-form-item :label="$t('agv.taskNo')">
        <el-text>{{ form.taskCode }}</el-text>
      </el-form-item>
      <el-form-item :label="$t('agv.priority')" prop="initPriority" width="120px">
        <el-select v-model="form.initPriority" clearable>
          <el-option v-for="item in priorityList" :key="item.id" :label="item.id" :value="item.name"/>
        </el-select>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="success" v-if="!showDetail" @click="handleChangeClick" size="default">{{
            $t('agv.submit')
          }}
        </el-button>
        <el-button type="info" @click="handleCancelClick" size="default">{{ $t('agv.cancel') }}</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref, reactive, defineExpose } from 'vue'
import { modifyTaskPriority } from '@/api/mes/agv'
import { useMessage } from '@/hooks/message'
import useI18n from '@/hooks/language'
const { t } = useI18n();
const form = ref({})
const visible = ref(false)
const openDialog = (formData) => {
  visible.value = true
  form.value = JSON.parse(JSON.stringify(formData))
  // form.value=formData
}
const handleCancelClick = () => {
  form.value = {}
  visible.value = false
}
const priorityList = reactive([
  //优先级列表
  {
    id: 1,
    name: 1,
  },
  {
    id: 2,
    name: 2,
  },
  {
    id: 3,
    name: 3,
  },
  {
    id: 4,
    name: 4,
  },
  {
    id: 5,
    name: 5,
  },
])

const handleChangeClick = () => {
  modifyTaskPriority({
    taskCode: form.value.taskCode,
    secondPriority: form.value.initPriority
  }).then(res => {
    if (res.code == 200) {
      useMessage().success(t('agv.modifySuccessfully'))
      handleCancelClick()
    } else {
      useMessage().error(res.message)
    }
  })
}
defineExpose({
  openDialog
})
</script>

<style lang="scss" scoped>
</style>
